function login(app) {
  console.log(app)
  var that = this;
  wx.showLoading({ title: '正在登陆' });
  wx.login({
    success: function (res) {
      console.log("微信端登录成功");
      console.log(app)
      var code = res.code;
      app.globalData.code = code
      console.log(res)
      wx.request({
        url: app.globalData.host + '/api/account/wxopenlogin',
        data: {
          code: code,
          storeid: app.globalData.storeId,
          storeAppId: app.globalData.storeAppId
        },
        success: function (res) {
          console.log(res);
          wx.hideLoading();
          if (res.data.Code != 0) {
            console.log("服务端登录发生错误");
            wx.showModal({
              title: '提示',
              content: res.data.Message,
              showCancel: false
            })
            return;
          }
          console.log("服务端登录成功");
          app.globalData.userInfo=res.data.Data;
          if (app.onLineCallback) {
            app.onLineCallback();
          }
        },
        fail:function(res){
          console.log("服务器失败")
          wx.hideLoading();
          wx.showModal({
            title: '提示',
            content: res.errMsg,
            showCancel: false
          })
        }
      })
    }, fail: function (res) {
      console.log(res)
      console.log("微信失败")
      wx.hideLoading();
       wx.showModal({
        title: '提示',
        content: res.errMsg,
        showCancel: false
      })
    }
  })
}

module.exports = {
  login: login
}